import cv2
import numpy as np
import matplotlib.pyplot as plt
 
img_path = "/Users/mac/Documents/Learning/LearningOpencv/datasets/1.jpg"

#载入原图
img = cv2.imread(img_path)

kernel = np.ones((50,50),np.uint8)
#礼帽
tophat = cv2.morphologyEx(img, cv2.MORPH_TOPHAT, kernel)
cv2.imshow('tophat', tophat)

#黑帽
blackhat  = cv2.morphologyEx(img,cv2.MORPH_BLACKHAT, kernel)
cv2.imshow('blackhat ', blackhat )

cv2.waitKey(0)
